package com.cskaoyan._19collection._05list.arraylist;

import java.util.ArrayList;

/**
 * @author Macro_Ray
 * @since 2024/3/30 16:50
 */
/*
 * 定义一个集合，存入三个手机对象，
 * 分别为：小米，1000。苹果，8000。锤子2999。
 * 定义一个方法，将价格低于3000的手机信息返回。*/
public class ArrayListTest6 {
    public static void main(String[] args) {
        ArrayList<Phone> phoneList = new ArrayList<>();
        phoneList.add(new Phone("小米", 1000));
        phoneList.add(new Phone("苹果", 8000));
        phoneList.add(new Phone("锤子", 2999));

        ArrayList<Phone> phoneInfoList = getLowPricePhontInfo(phoneList);

        for (int i = 0; i < phoneInfoList.size(); i++) {
            Phone phone = phoneInfoList.get(i);
            System.out.println(phone.getPhoneName() + "，" + phone.getPhonePrice());
        }
    }

    public static ArrayList<Phone> getLowPricePhontInfo(ArrayList<Phone> phoneList) {
        ArrayList<Phone> resultList = new ArrayList<>();
        for (int i = 0; i < phoneList.size(); i++) {
            Phone phone = phoneList.get(i);
            int phonePrice = phone.getPhonePrice();
            if (phonePrice < 3000) {
                resultList.add(phone);
            }
        }
        return resultList;
    }
}

class Phone {
    private String phoneName;
    private int phonePrice;

    public Phone() {
    }

    public Phone(String phoneName, int phonePrice) {
        this.phoneName = phoneName;
        this.phonePrice = phonePrice;
    }

    public String getPhoneName() {
        return phoneName;
    }

    public void setPhoneName(String phoneName) {
        this.phoneName = phoneName;
    }

    public int getPhonePrice() {
        return phonePrice;
    }

    public void setPhonePrice(int phonePrice) {
        this.phonePrice = phonePrice;
    }
}
